package com.yxh.lib_base.util.photo

import android.content.Intent
import android.provider.MediaStore
import androidx.fragment.app.Fragment
import com.yxh.lib_base.util.photo.picture_selector.PictureSelectorImpl

/**
 * 作者 : yuan_xh
 * 时间 : 2022/7/7 10:12
 * 说明 : 图片选择工具类 ,参照 [IPhotoSelectorEngine]
 *
 * 使用方法：
 *    HWorkPhotoUtils.getInstance().openPhotoSingle(mActivity, (mediaType, path) -> { }
 *
 * @param mSelectorEngine 可修改{[PictureSelectorImpl]]}
 */
class PhotoUtils : IPhotoSelectorEngine by mSelectorEngine {
    companion object {
        private var mSelectorEngine: IPhotoSelectorEngine = PictureSelectorImpl()

        @JvmStatic
        val instance: PhotoUtils by lazy(LazyThreadSafetyMode.NONE) { PhotoUtils() }
    }

    /**
     * 更换引擎
     * */
    fun initEngine(engine: IPhotoSelectorEngine) {
        mSelectorEngine = engine
    }

    /**
     * 打开系统的相册 - 视频跟图片
     * */
    fun Fragment.openSystemImgOrVideo(requestCode: Int) {
        Intent(Intent.ACTION_PICK).apply {
            setDataAndType(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                MimeType.SYSTEM_ALL
            )
        }.let {
            startActivityForResult(it, requestCode)
        }
    }
}